#include <huniplacer_3d/Picking.h>

#include <GL/gl.h>
#include <GL/freeglut.h>

#include <huniplacer_3d/huniplacer_3d.h>

#include <string>

#include <iostream>

unsigned char Picking::id_counter[] = {1, 0, 0};

Picking::Picking(std::string name) {
	id[0] = id_counter[0];
	id[1] = id_counter[1];
	id[2] = id_counter[2];
	
	this->name = name;
	
	if (++id_counter[0] == 0) {		
		if(++id_counter[1] == 0) {
			id_counter[2]++;
		}
	}
	
	getHuniplacerData()->modeldata.picking_ids.push_back(this);
}

void Picking::set_color3f(float r, float g, float b) {
	if (getHuniplacerData()->modeldata.picking) {
		glColor3ub(id[0], id[1], id[2]);
	} else {
		glColor3f(r, g, b);
	}
}
void Picking::set_color4f(float r, float g, float b, float a) {
	if (getHuniplacerData()->modeldata.picking) {
		glColor3ub(id[0], id[1], id[2]);
	} else {
		glColor4f(r, g, b, a);
	}
}

bool Picking::compare_id(unsigned char* cmp) {
	if (	id[0] == cmp[0] &&
			id[1] == cmp[1] &&
			id[2] == cmp[2] ) {
		return true;		
	}
	
	return false;
}
